import Vue from 'vue'
import ElementUI, { Message } from 'element-ui'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/common.css'
import '@/packages/flexible.js'

Vue.config.productionTip = false


//将axios挂载到vue原型上
Vue.prototype.$http = axios;
axios.defaults.baseURL = '/api'; //基础地址
axios.defaults.timeout = 8000;  //超时时间
axios.interceptors.response.use(function(response) { //响应拦截器
  let res = response.data;
  return res;
})

// 响应拦截器的异常处理
axios.interceptors.response.use(response => {
  if (response.code == 0) {
    return response
  } else if (response.code == -1) {
    Message({
      message: response.message,
      type: 'error'
    })
    return response
  }else {
    return response
  }
})

Vue.use(ElementUI);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
